import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'
import { classToPlain } from 'class-transformer'
@Injectable()
export class TransformInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    return next.handle().pipe(
      map((data: any) => {
        console.log('拦截器-data',data);
        return {
          result: classToPlain(data||{}),// classToPlain关键的一个方法,不使用那么实体类中使用排除字段的不生效
          code: 0,
          message: '请求成功'
        }
      })
    );
  }
}
